

/**
 * 创建entity Cylinder
 */
import Entity from '../Entity'

export default class Cylinder extends Entity {

  /**
   * 创建一个Cylinder实体对象
   * @param {*} position 
   * @param {*} options 
   */
  constructor(positions, options = {}) {
    super()
    this._positions = positions
    this._height = options.height || 0
    this._top = options.top || 0
    this._bottom = options.bottom || 0
    this._type = 'cylinder'
    this._style = {
      ...options
    }

    this.delegate = new Cesium.Entity({cylinder: {}})
    this.mounted()
  }

  /**
  * 初始化对象属性
  */

  mounted() {
    this.style = this._style
    this.positions = this._positions
    this.height = this._height
    this.top = this._top
    this.bottom = this._bottom
  }

  /** 
  * @param {*} style Circle的样式
  * @returns 
  */

  setStyle(style) {
    if (!style) return
    delete style['position']
    Object.assign(this._style, { ...style })
    Object.assign(this.delegate.cylinder, { 
      topRadius : style.top || this._top,
      bottomRadius : style.bottom || this._bottom,
      length : style.height || this._height,
      ...this._style
    })
  }

  get style(){
    return this._style
  }

  set style(val){
    Object.assign(this._style , {...val})
    Object.assign(this.delegate.cylinder , {
      topRadius : this._style.top || this._top,
      bottomRadius : this._style.bottom || this._bottom,
      length : this._style.height || this._height,
      ...this._style
    })
  }

  get positions() {
    return this._positions
  }

  set positions(val) {
    this._positions = val
    this.delegate.position = this._positions
  }

  get top(){
    return this._top
  }

  set top(val){
    this._top = val
    this.delegate.cylinder.topRadius = this._top
  }

  get bottom(){
    return this._bottom
  }

  set bottom(val){
    this._bottom = val
    this.delegate.cylinder.bottomRadius = this._bottom
  }

  get height(){
    return this.height
  }

  set height(val){
    this._height = val
    this.delegate.cylinder.length = this._height
  }

}
